
//
//  test.m
//  go2
//
//  Created by 袁飞 on 12-7-21.
//
//

#import "test.h"
#import "FObject.h"
#import "FUtil.h"
#import "FListView.h"
#import "ButtonHandle.h"
#import "FProgressBar.h"
#import "FSwitch.h"

@implementation test
-(id)init{
  [super init];
  srand((unsigned int)time(NULL));
  //[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
  /*CCSprite* sp1 = [CCSprite spriteWithSpriteFrameName:@"bar_1.png"];
  [sp1 setPosition:ccp(100,200)];
  [self addChild:sp1];
  
  CCSprite* sp2 = [CCSprite spriteWithSpriteFrameName:@"bar_bg_1.png"];
  [sp2 setPosition:ccp(100,150)];
  [self addChild:sp2];

  
  FProgressBar* bar = [[FProgressBar alloc] initWithBK:@"bar_bg_1.png" Bar:@"bar_1.png" Total:100];
  [self addChild:bar];
  [bar setPosition:ccp(100, 100)];*/
  
  [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"fish.plist"];
  FObject* o = [FObject FObjectFromXmlFile:@"obj.xml" WithDict:nil];
  [self addChild:o];
  return self;
}

-(void)change:(NSString*)name{
  //[self removeChild:o_ cleanup:false];
  NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  [dict setObject:name forKey:@"fishno"];
  FObject* o = [FObject FObjectFromXmlFile:@"obj.xml" WithDict:dict];
  [self addChild:o];
  //[o_ setPosition:ccp(100,50)];
  //[o2 runActionRepeated:@"eat" WithSprite:@"test"];
  FRandomAI *ai = [[FRandomAI alloc] initWithFObject:o];
  [o setAi:ai]; 
  [o startAi];
  
  [[ButtonHandle sharedButtonHandle] addObject:o];
}

-(void)showList:(bool)show{
  if (show) {
    [self addChild:list_];
  }else{
    [self removeChild:list_ cleanup:false];
  }
}

@end
